package util;

import Ut.DBUtil;
import com.mysql.cj.jdbc.MysqlDataSource;

import java.math.BigDecimal;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Scanner;

public class DEMO4 {
    public static void main(String[] args) {
        Connection connection=null;
        PreparedStatement preparedStatement=null;
        ResultSet resultSet=null;
        Scanner scanner=new Scanner(System.in);
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            connection= DBUtil.getConnect();
            String sql="insert into bank_account(name,balance) values(?,?)";
            preparedStatement=connection.prepareStatement(sql);
            System.out.println("请输入你要插入人员的名字");
            String name=scanner.nextLine();
            System.out.println("请输入你要插入人员的余额");
            BigDecimal balance=new BigDecimal(scanner.nextLine());
            preparedStatement.setString(1,name);
            preparedStatement.setBigDecimal(2,balance);
            int row=preparedStatement.executeUpdate();
            if(row==1) {
                System.out.println("插入成功");
            }else{
                System.out.println("插入失败");
            }

        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            DBUtil.close(connection,preparedStatement,null,scanner);
        }
    }
}
